<template>
	<el-card shadow="hover" :body-style="{ paddingBottom: '0' }" >
		<el-form :model="state.queryParams" ref="queryForm" :inline="true">
			<el-form-item>
				<el-button round type="primary" icon="ele-Plus" @click="openAddDownLoad"> 新 增 </el-button>
			</el-form-item>
		</el-form>
	</el-card>
	<el-card class="full-table" shadow="hover" style="margin-top: 8px" >
		<el-table :data="state.articleData" style="width: 100%" v-loading="state.loading" border>
			<el-table-column type="id" label="序号" width="55" align="center" />
			<el-table-column prop="title" label="标题" min-width="150" header-align="center" show-overflow-tooltip />
			<el-table-column prop="fileUrl" label="文件地址"  header-align="center" show-overflow-tooltip />
			<el-table-column prop="fileType" label="文件类型"  header-align="center" show-overflow-tooltip />
			<el-table-column prop="fileSize" label="文件大小" align="center" show-overflow-tooltip>
				<template #default="scope">
					{{scope.row.fileSize}}/kb
				</template>
			</el-table-column>
			<el-table-column prop="audit" label="审核状态" align="center" show-overflow-tooltip>
				<template #default="scope">
					<el-switch
					    v-model="scope.row.audit"
					    class="ml-2"
					    inline-prompt
						disabled
					    style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
					    active-text="已审核"
					    inactive-text="未审核"
					  />
				</template>
			</el-table-column>
			<el-table-column prop="hits" label="点击量" align="center" show-overflow-tooltip />
					<el-table-column prop="downSum" label="下载量" align="center" show-overflow-tooltip />
			<el-table-column prop="updateTime" label="更新时间" align="center" show-overflow-tooltip />
			<el-table-column label="操作" width="260" fixed="right" align="center" show-overflow-tooltip>
				<template #default="scope">
					<el-button icon="ele-Delete" size="small" text type="danger" @click="delArticle(scope.row)" v-auth="'sysFile:delete'"> 删除 </el-button>
					<el-button icon="ele-Edit" size="small" text type="primary" @click="openEditArticle(scope.row)" v-auth="'sysFile:update'"> 编辑 </el-button>
				</template>
			</el-table-column>
		</el-table>
		<div>
			<el-pagination
				v-model:currentPage="state.tableParams.page"
				v-model:page-size="state.tableParams.pageSize"
				:total="state.tableParams.total"
				:page-sizes="[10, 20, 50, 100]"
				small
				background
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
			/>
		</div>
		
	</el-card>
	<EditDownLoadTemp ref="editDownLoadTempRef"  :title="state.editDownLoadTitle"  @handleQuery="handleQuery" />
</template>
<script lang="ts" setup name="downLoad">
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { pagecms_download, editcms_download,delcms_download } from '/@/api/CMS/cms_download'
import EditDownLoadTemp from '/@/views/CMS/cms_Template/common/downloadTemp.vue';


// const baseUrl = window.__env__.VITE_API_URL;
const editDownLoadTempRef = ref<InstanceType<typeof EditDownLoadTemp>>();
const props = defineProps({
	isshow: false as any,
});
const state = reactive({
	loading: false,
	articleData: [] as any,
	queryParams: {
		fileName: undefined,
	},
	tableParams: {
		page: 1,
		pageSize: 10,
		total: 0 as any,
	},
	filetypeData:[],
	dialogUploadVisible: false,
	diaglogEditFile: false,
	fileList: [] as any,
	fileName: '',
	editDownLoadTitle:'',
	columnId:'',
});
onMounted(async () => {
	handleQuery();
});


// 查询操作
const handleQuery = async () => {
	state.loading = true;
	let params = Object.assign(state.queryParams, state.tableParams);
	var res = await pagecms_download(params);
	state.articleData = res.data.result?.items ?? [];
	state.tableParams.total = res.data.result?.total;
	state.loading = false;
};
//移动
const movearticle = async () => {
	
};
//新增下载
const openAddDownLoad=async()=>{
	state.editDownLoadTitle="新增下载";
	editDownLoadTempRef.value?.openDialog({columnId:state.columnId});
};
// 删除
const delArticle = (row: any) => {
	ElMessageBox.confirm(`确定删除：【${row.title}】?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	}).then(async () => {
			await delcms_download({ id: row.id });
			handleQuery();
			ElMessage.success('删除成功');
		})
		.catch(() => {});
};
// 改变页面容量
const handleSizeChange = (val: number) => {
	state.tableParams.pageSize = val;
	handleQuery();
};
const movebtnshow=()=>{
	
};

// 打开组件
const openUnit = (row: any) => {
	state.columnId=row.id;
	//ruleForm.value = JSON.parse(JSON.stringify(row));
};
// 改变页码序号
const handleCurrentChange = (val: number) => {
	state.tableParams.page = val;
	handleQuery();
};
// 打开编辑页面
const openEditArticle = (row: any) => {
	state.editDownLoadTitle="修改下载";
	editDownLoadTempRef.value?.openDialog(row);
};
// 文件渲染完成
const renderedHandler = () => {};
// 文件渲染失败
const errorHandler = () => {};
//将属性或者函数暴露给父组件
defineExpose({ openUnit });
</script>
